﻿using Kele.Core.Exceptions;
using System.Collections.Generic;

namespace Kele.Activity.Core
{
    public static class AppError
    {
        /// <summary>
        /// 抛出异常ApiException
        /// </summary>
        /// <param name="error">错误消息</param>
        public static KeleException ApiException(string error)
        {
            return new KeleException(error, 3000);
        }

        /// <summary>
        /// 通过code抛出异常ApiException
        /// </summary>
        /// <param name="code">错误代码</param>
        public static KeleException ApiException(int code)
        {
            var error = GetErrorByCode(code);
            return new KeleException(error, code);
        }

        public static string GetErrorByCode(int code)
        {
            return _codeErrors.ContainsKey(code) ? _codeErrors[code] : "未知的错误信息";
        }

        private static readonly Dictionary<int, string> _codeErrors = new Dictionary<int, string>
        {
            {1000, "成功"},
            {2000, "数据验证失败"},
            {3000, "系统错误"},
            {3001, "未验证"},
            {4001, "没有找到活动"}, 
            {4002, "没有找到Form"},
        };
    }
}